package com.vastcom.seal.generater.action;

import com.vastcom.seal.generater.to.Parm;
import com.vastcom.seal.generater.util.Seal;
import com.vastcom.seal.generater.util.SealCircle;
import com.vastcom.seal.generater.util.SealFont;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@CrossOrigin
@Controller
@RequestMapping("/public")
public class PublicAction {

    @Value("${seal.generate.path}")
    private String generatepath;


    @PostMapping("generateOfficeSeal_1")
    @ResponseBody
    public HashMap generateOfficeSeal_1(@RequestBody Parm parm) throws Exception{
        HashMap m=new HashMap();

        try {
            Seal.builder()
                    .size(200)
                    .borderCircle(SealCircle.builder().line(4).width(95).height(95).build())
                    .mainFont(SealFont.builder().text(parm.getOfficename()).size(22).space(22.0).margin(4).build())
                    .centerFont(SealFont.builder().text("★").size(60).build())
                    .titleFont(SealFont.builder().text(parm.getSubtitle()).size(16).space(8.0).margin(54).build())
                    .build()
                    .draw(generatepath+parm.getOfficename()+"T1"+".png");
            m.put("msg","ok");
            m.put("obj",generatepath+parm.getOfficename()+"T1"+".png");
        } catch (Exception e) {
            e.printStackTrace();
            m.put("msg","error");
        }


        return m;
    }


    @PostMapping("generateSeal_T2")
    @ResponseBody
    public HashMap generateSeal_T2(@RequestBody Parm parm) throws Exception{
        HashMap m=new HashMap();


        try {
            Seal.builder()
                    .size(300)
                    .borderCircle(SealCircle.builder().line(5).width(140).height(140).build())
                    .mainFont(SealFont.builder().text(parm.getOfficename()).size(35).space(35.0).margin(10).build())
                    .centerFont(SealFont.builder().text("★").size(100).build())
                    .titleFont(SealFont.builder().text(parm.getSubtitle()).size(22).space(10.0).margin(68).build())
                    .build()
                    .draw(generatepath+parm.getOfficename()+"T2"+".png");

            m.put("msg","ok");
            m.put("obj",generatepath+parm.getOfficename()+"T2"+".png");
        } catch (Exception e) {
            e.printStackTrace();
            m.put("msg","error");
        }

        return m;
    }


    @PostMapping("generateOfficeSeal_T3")
    @ResponseBody
    public HashMap generateOfficeSeal_T3(@RequestBody Parm parm) throws Exception{
        HashMap m=new HashMap();


        try {
            Seal.builder()
                    .size(300)
                    .borderCircle(SealCircle.builder().line(3).width(144).height(100).build())
                    .borderInnerCircle(SealCircle.builder().line(1).width(140).height(96).build())
                    .mainFont(SealFont.builder().text(parm.getOfficename()).size(25).space(12.0).margin(10).build())
                    .centerFont(SealFont.builder().text(parm.getSealnum()).size(20).build())
                    .titleFont(SealFont.builder().text(parm.getSubtitle()).size(20).space(9.0).margin(64).build())
                    .build()
                    .draw(generatepath+parm.getOfficename()+"T3"+".png");

            m.put("msg","ok");
            m.put("obj",generatepath+parm.getOfficename()+"T3"+".png");
        } catch (Exception e) {
            e.printStackTrace();
            m.put("msg","error");
        }

        return m;
    }


    @PostMapping("generatePrivateSeal_Type_1")
    @ResponseBody
    public HashMap generatePrivateSeal_Type_1(@RequestBody Parm parm) throws Exception{

        HashMap m=new HashMap();


        try {
            Seal.builder()
                    .size(300)
                    .borderSquare(16)
                    .mainFont(SealFont.builder().text(parm.getPersonname()).size(120).build())
                    .build()
                    .draw(generatepath+parm.getPersonname()+"T1"+".png");


            m.put("msg","ok");
            m.put("obj",generatepath+parm.getPersonname()+"T1"+".png");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return m;


    }



}
